# 取收盘价




database = MongoDB.MongoDB("10.13.38.31", "27017")
datetime1 = datetime.datetime(2017, 12, 1)
datetime1 = Gadget.ToUTCDateTime(datetime1)
datetime2 = datetime.datetime(2018, 10, 18)
datetime2 = Gadget.ToUTCDateTime(datetime2)


df = get_price('000001.XSHE', end_date='2018-07-13',frequency='1d',fields=['close'],count=60)
# 取换手率
tr = get_fundamentals_continuously(query(valuation.turnover_ratio).filter(valuation.code.in_(['000001.XSHE'])),\
                                   end_date='2018-07-13',count=60)['turnover_ratio']
# 换手率转数组
ratio = (np.nan_to_num(tr.values)/100).ravel()
# 收盘价转数组
close = df.values.ravel()
# 计算累积换手率
ratio[0:-1] *= np.cumprod(1-ratio[::-1],0)[::-1][1:]

def cost_distribution(x,c,q=60):
    '''对商品价格进行数字化分组'''
    cuts = cut(x,q) # x是价格序列
    # 获取数组尺寸,取得有效值(分组号及筹码表)
    mask = np.isfinite(cuts) &amp;  np.isfinite(c)
    # 标记无效值
    cuts[~mask] = q
    # 汇总统计
    ctbe = np.bincount(cuts.astype(int64)[mask],weights=c[mask])
    # 统计结果
    return ctbe

# 筹码分布统计
cost = cost_distribution(close,ratio)